﻿/**
 * Proyecto: Cognitum
 * Global IT Services 2008
 * @author Mislas
 */
Cognitum.Polizas.Tramite.Entity = function(){
    if (LOG.isDebugEnabled()) {
        LOG.debug('[Cognitum.Polizas.Tramite.Entity.ctor] <-');
    }
    Cognitum.Polizas.Tramite.Entity.superclass.constructor.call(this, false, true);
}

Ext.extend(Cognitum.Polizas.Tramite.Entity, Karma.Core.Entity, {
    id: 'Tramites.Entity',
    name: 'Tramites',
    columns: [{
        Name: 'Id',
        Property: 'Id',
        Mostrar: false
    }, {
        Name: 'Folio',
        Property: 'Folio'
    }],
    titleProperty: new Ext.XTemplate(
			'<tpl if="!Ext.isEmpty(values.Folio)">Folio : [{values.Folio}]</tpl>',
			'<tpl if="Ext.isEmpty(values.Folio)">OT : [{values.Id}]</tpl>'),
	link: {
	    displayProperty: new Ext.XTemplate(
			'<tpl if="!Ext.isEmpty(values.Folio)">Folio : [{values.Folio}]</tpl>',
			'<tpl if="Ext.isEmpty(values.Folio)">OT : [{values.Id}]</tpl>')
	},
	onOpen: function(id, listeners, useXtype, editorProperties) {
		if (LOG.isDebugEnabled()) {
            LOG.debug('[Poliza.onOpen] <-');
        }

        var editorWin = Karma.WinManager.Instance.getIfExist(this, id);
        if (Ext.isEmpty(editorWin)) {            
            this.useInvoker(Karma.Conf.GetMethod, id, {
                fn: function(tramite) {
					// es poliza
                    if (Ext.isEmpty(tramite.EstatusEndoso)) {
						var entity = Karma.Core.ModuleManager.Instance.getEntity('Polizas');
						entity.openPoliza(tramite, listeners, editorProperties);
					} else { // es endoso
						var entity = Karma.Core.ModuleManager.Instance.getEntity('Endosos');
						entity.openEndoso(tramite, listeners, editorProperties);
					}
                },
                scope: this
            });                        
        }
        else {           
            editorWin.show();
        }
	}
});

Cognitum.Tramite = Cognitum.Polizas.Tramite.Entity;
